package cn.edu.zut.hhr.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.edu.zut.hhr.exceptions.CheckException;
import java.util.Arrays;

/**
 *
 * @author hhr
 * @date 2021/6/17
 */
public class CheckUtil {
    private static final Logger logger = LoggerFactory.getLogger(CheckUtil.class);

    public static void check(boolean condition, String msgKey, Object... args) {
        if (!condition) {
            fail(msgKey, args);
        }
    }

    public static void notEmpty(String str, String msgKey, Object... args) {
        if (str == null || str.isEmpty()) {
            fail(msgKey, args);
        }
    }

    public static void notNull(Object obj, String msgKey, Object... args) {
        if (obj == null) {
            fail(msgKey, args);
        }
    }


    public static void fail(String msgKey, Object... args) {
        logger.error("error. message: " + msgKey + ", args: " + Arrays.toString(args));
        throw new CheckException(msgKey);
    }
}
